package Three;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Three {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.hashCode();
		while (scan.hasNext()) {
			String s = scan.next();
			if (s.equals("!!!!!")) {
				break;
			} else {
				if (map.containsKey(s)) {
					map.put(s, map.get(s) + 1);
				} else {
					map.put(s, 1);
				}
			}
		}
		ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
		Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
				if (o1.getValue() != o2.getValue()) {
					return o2.getValue() - o1.getValue();
				} else {
					return o1.getKey().compareTo(o2.getKey());
				}
			}
		});
		System.out.println(map.size());
		for (int i = 0; i < 10; i++) {
			System.out.println(list.get(i).toString());
		}
		scan.close();
	}

}
